//package com.eastfair.gateway.filters;
//
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.core.util.URLUtil;
//import com.eastfair.core.base.R;
//import com.eastfair.core.context.ContextConstants;
//import com.eastfair.core.exception.BizException;
//import com.eastfair.handler.EfTokenHandler;
//import com.eastfair.jwt.model.AuthInfo;
//import com.eastfair.jwt.service.JwtService;
//import com.eastfair.properties.IgnoreProperties;
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.google.common.collect.Maps;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.MDC;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.core.io.buffer.DataBuffer;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.Map;
//
///**
// * 鉴权过滤器
// *
// * @Author ligang
// * @Date 2020/3/16 23:33
// */
//@Slf4j
//@WebFilter("/*")
//public class CorsFilter implements Filter {
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse resp = (HttpServletResponse) servletResponse;
//
//        // 告诉浏览器允许所有的域访问
//        // 注意 * 不能满足带有cookie的访问,Origin 必须是全匹配
//        // resp.addHeader("Access-Control-Allow-Origin", "*");
//        // 解决办法通过获取Origin请求头来动态设置
//        String origin = request.getHeader("Origin");
//        if (StringUtils.isNotBlank(origin)) {
//            resp.addHeader("Access-Control-Allow-Origin", origin);
//        }
//        // 允许带有cookie访问
//        resp.addHeader("Access-Control-Allow-Credentials", "true");
//
//        // 告诉浏览器允许跨域访问的方法
//        resp.addHeader("Access-Control-Allow-Methods", "*");
//
//        // 告诉浏览器允许带有Content-Type,header1,header2头的请求访问
//        // resp.addHeader("Access-Control-Allow-Headers", "Content-Type,header1,header2");
//        // 设置支持所有的自定义请求头
//        String headers = request.getHeader("Access-Control-Request-Headers");
//        if (StringUtils.isNotBlank(headers)) {
//            resp.addHeader("Access-Control-Allow-Headers", headers);
//        }
//
//        // 告诉浏览器缓存OPTIONS预检请求1小时,避免非简单请求每次发送预检请求,提升性能
//        resp.addHeader("Access-Control-Max-Age", "3600");
//
//        chain.doFilter(request, resp);
//    }
//
//}
